package game.fury;

import android.graphics.Canvas;
import android.graphics.Paint;
import sheep.game.Sprite;
import sheep.game.State;
import sheep.graphics.Font;
import sheep.graphics.Image;
import sheep.gui.TextButton;
import sheep.gui.WidgetAction;
import sheep.gui.WidgetListener;

public class InstructionScreen extends State implements WidgetListener {
	private Image[] instruction = {new Image(R.drawable.instructions_1), new Image(R.drawable.instructions_2),new Image(R.drawable.instructions_3),
									new Image(R.drawable.instructions_4),new Image(R.drawable.instructions_5)};
	
	private Sprite background;
	
	private TextButton next;
	
	private TextButton prev;
	
	private TextButton quit;
	
	boolean hasnext;
	boolean hasprev;
	int i;
	
	/**
	 * Displays a series of pictures with instructions. 
	 * @author Marius
	 */
	public InstructionScreen(){
		hasnext = true;
		hasprev = false;
		i = 0;
		background = new Sprite(instruction[i]);
		background.setPosition(240,400);
		
		
		prev = new TextButton(250,700, "Previous", new Paint[] {Font.WHITE_SANS_BOLD_20, Font.WHITE_SANS_BOLD_20} );
		addTouchListener(prev);
		prev.addWidgetListener(this);
		
		next = new TextButton(350,700, "Next", new Paint[] {Font.WHITE_SANS_BOLD_20, Font.WHITE_SANS_BOLD_20} );
		addTouchListener(next);
		next.addWidgetListener(this);
		
		quit = new TextButton(100,700, "Menu", new Paint[] {Font.WHITE_SANS_BOLD_20, Font.WHITE_SANS_BOLD_20} );
		addTouchListener(quit);
		quit.addWidgetListener(this);
		
	}
	
	public void draw(Canvas canvas){
		background.draw(canvas);
		if(hasnext){
			next.draw(canvas);
		}
		if(hasprev){
			prev.draw(canvas);
		}
		quit.draw(canvas);
		
	}
	
	public void update(float dt){
		background.update(dt);
		
	}

	@Override
	public void actionPerformed(WidgetAction action) {
		if(action.getSource().equals(next)){
			if(i<instruction.length){
				hasprev = true;
				i++;	
				background = new Sprite(instruction[i]);
				background.setPosition(240,400);
			}
			if(i ==(instruction.length-1)) hasnext = false;
		}
		if(action.getSource().equals(prev)){
			if(i>0){
				hasnext = true;
				i--;	
				background = new Sprite(instruction[i]);
				background.setPosition(240,400);
			}
			else hasprev = false;
		}
		
		
		if(action.getSource().equals(quit)) getGame().popState();
	}
	
}
